/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;
import java.util.ArrayList;
import java.sql.ResultSet;
import DTO.SANPHAMDTO;
import UNTIL.DataProvider;
import java.sql.SQLException;
/**
 *
 * @author NGUYEN
 */
public class SANPHAMDAO {
    public ArrayList<SANPHAMDTO> laydanhsachsanpham()throws Exception
    {
        ArrayList<SANPHAMDTO> ds = new ArrayList<SANPHAMDTO>();
        DataProvider pro = new DataProvider();
        try
        {
          String query = "SELECT * FROM sanpham";
          pro.open();
          ResultSet rs = pro.excutequery(query);
          while(rs.next())
          {
              SANPHAMDTO dao = new SANPHAMDTO();
              dao.setMasp(Integer.parseInt(rs.getString("masp")));
              dao.setTensp(rs.getString("tensp"));
              dao.setDongia(Double.parseDouble(rs.getString("dongia")));
              dao.setMaloai(Integer.parseInt(rs.getString("maloai")));
              ds.add(dao);
          }
        }
        catch(SQLException | NumberFormatException e)
        {
            throw e;
        }
        finally
        {
            pro.close();
        }
        return ds;
    }
}
